from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class News(models.Model):
	heading = models.CharField(max_length=200)
	text = models.TextField()
	publishDate = models.DateTimeField()
	def __unicode__(self):
		return self.heading

class Label(models.Model):
	label = models.CharField(max_length=200)
	def __unicode__(self):
		return self.label

class Project(models.Model):
	title = models.CharField(max_length=200)
	shortName = models.CharField(max_length=20)
	status = models.CharField(max_length=200)
	descriptionText = models.TextField()
	licenceName = models.CharField(max_length=200)
	licenceDescription = models.CharField(max_length=200)
	targetEnv = models.CharField(max_length=200)
	programmingLanguage = models.CharField(max_length=200)
	labels = models.ManyToManyField(Label)
	members = models.ManyToManyField(User, through='ProjectMembership')
	lastChange = models.DateTimeField()
	def __unicode__(self):
		return self.title

class ProjectMembership(models.Model):
	project = models.ForeignKey(Project)
	user = models.ForeignKey(User)
	dateJoined = models.DateTimeField()
	canDeleteProject = models.BooleanField()
	canAddUser = models.BooleanField()
	canChangeProjectDescription = models.BooleanField()
	def __unicode__(self):
		return self.user.username + " on " + self.project.title
	